<template>
  <div v-show="props.compType === 'input'">
    <el-form-item label="ID">
      <el-tooltip
        class="item"
        effect="dark"
        content="请注意,ID的修改可能会导致该组件相关事件失效！"
        placement="left"
      >
        <el-input
          class="input"
          v-model="props.id"
          @change="handlerChangeGetId"
        ></el-input>
      </el-tooltip>
    </el-form-item>
    <el-form-item label="字典key">
      <el-input class="input" v-model="props.dictionaryKey"></el-input>
    </el-form-item>
    <el-form-item label="标题">
      <el-input class="input" v-model="props.label"></el-input>
    </el-form-item>
    <el-form-item label="栅格">
      <el-input-number v-model="props.span" :min="1" :max="24" />
    </el-form-item>
    <el-form-item label="提示符">
      <el-input
        class="input"
        v-model="props.placeholder"
        placeholder="请输入提示符"
      />
    </el-form-item>
    <el-form-item label="栅格间隔">
      <el-input-number v-model="props.gutter" :min="0"></el-input-number>
    </el-form-item>
    <el-form-item label="标签宽度">
      <el-input-number
        v-model="props.labelWidth"
        :min="1"
        :max="200"
      ></el-input-number>
    </el-form-item>
    <el-form-item label="显示标签">
      <el-switch
        v-model="props.showLabel"
        @change="handlerChangeLabel"
      ></el-switch>
    </el-form-item>
    <el-form-item label="必填">
      <el-switch v-model="props.required"></el-switch>
    </el-form-item>
    <el-form-item label="清除">
      <el-switch v-model="props.clearable"></el-switch>
    </el-form-item>
    <el-form-item label="禁用">
      <el-switch v-model="props.disabled"></el-switch>
    </el-form-item>
    <el-form-item label="只读">
      <el-switch v-model="props.readonly"></el-switch>
    </el-form-item>
    <el-form-item label="默认值">
      <el-input class="input" v-model="props.modelValue"></el-input>
    </el-form-item>

    <el-divider>校验</el-divider>
    <el-form-item label="验证类型">
      <el-select v-model="props.rulesType" @change="handlerChangeRulesType">
        <el-option label="无" value="default" />
        <el-option label="电话" value="phone" />
        <el-option label="邮箱" value="email" />
        <el-option label="纯数字" value="number" />
        <el-option label="身份证" value="idcard" />
      </el-select>
    </el-form-item>
    <div v-for="(item, index) in props.rules" :key="index" class="rule-item">
      <el-input v-model="item.rule" placeholder="正则" size="small" />
      <p />
      <el-input v-model="item.msg" placeholder="自定义提示" size="small" />
      <div
        class="close-btn select-line-icon"
        @click="props.rules.splice(index, 1)"
      >
        <el-icon>
          <Remove />
        </el-icon>
      </div>
    </div>
    <div style="margin-left: 20px">
      <el-button
        style="padding-bottom: 0"
        icon="el-icon-circle-plus-outline"
        type="primary"
        link
        @click="addRuleItem"
      >
        添加选项
      </el-button>
    </div>
    <el-divider>Tooltip 配置</el-divider>
    
    <el-form-item label="启用提示">
      <el-switch v-model="props.tooltip.enabled" />
    </el-form-item>
    <template v-if="props.tooltip.enabled">
      <!-- <el-form-item label="前置图标">
      <el-input placeholder="请选择图标" v-model="props['prefix-icon']">
        <template #append>
          <el-icon @click="handlerPrefixSelectIcon" style="cursor: pointer">
            <Picture />
          </el-icon>
        </template>
      </el-input>
    </el-form-item>
    <el-form-item label="后置图标">
      <el-input placeholder="请选择图标" v-model="props['suffix-icon']">
        <template #append>
          <el-icon @click="handlerSuffixSelectIcon" style="cursor: pointer">
            <Picture />
          </el-icon>
        </template>
      </el-input>
    </el-form-item> -->
    <el-form-item label="前缀">
      <el-input v-model="props.prepend"></el-input>
    </el-form-item>
    <el-form-item label="后缀">
      <el-switch v-model="props.append"></el-switch>
    </el-form-item>
      <el-form-item label="提示内容">
        <el-input v-model="props.tooltip.content" />
      </el-form-item>
      <el-form-item label="提示位置">
        <el-select v-model="props.tooltip.placement">
          <el-option label="上方" value="top" />
          <el-option label="下方" value="bottom" />
          <el-option label="左侧" value="left" />
          <el-option label="右侧" value="right" />
        </el-select>
      </el-form-item>
      <el-form-item label="提示主题">
        <el-select v-model="props.tooltip.effect">
          <el-option label="Dark" value="dark" />
          <el-option label="Light" value="light" />
        </el-select>
      </el-form-item>
      <el-form-item label="提示图标">
        <el-input v-model="props.tooltip.icon">
        </el-input>
      </el-form-item>
    </template>

    <icon-dialog
      v-model="props['suffix-icon']"
      v-model:visible="iconDialogVisible_suffix"
    />
    <icon-dialog
      v-model="props['prefix-icon']"
      v-model:visible="iconDialogVisible_prefix"
    />
  </div>
</template>
<script lang="ts">
const defaultRules = {
  phone: {
    rule: "0?(13|14|15|17|18|19)[0-9]{9}",
    msg: "您输入的电话号码不符合规则",
  },
  email: {
    rule: "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}",
    msg: "您输入的邮件地址不符合规则",
  },
  number: { rule: "^[0-9]*$", msg: "您输入的内容不符合纯数字规则" },
  idcard: {
    rule: "\\d{17}[\\d|x]|\\d{15}",
    msg: "您输入的身份证号码不符合规则",
  },
};
/**
 * input的配置项
 */
import { changeId, type FormDesignerMixin } from "../mixin/FormDesignerMixin";
import { Component, Prop } from "web-decorator-vue";
import iconDialog from "../../iconDialog.vue";
import { Remove } from "@element-plus/icons-vue";

@Component({
  name: "input-config",
  mixins: [changeId],
  components: {
    Remove,
    iconDialog,
  },
})
export default class FDInput implements FormDesignerMixin {
  // TODO 补齐作用
  @Prop() props: any;
  // TODO 补齐作用
  @Prop() getFormId: any;
  // TODO 补齐作用
  val: string = "";
  // TODO 补齐作用
  iconDialogVisible_suffix: boolean = false;
  // TODO 补齐作用
  iconDialogVisible_prefix: boolean = false;
  // TODO 补齐作用
  handlerChangeLabel(val: any) {
    this.props.labelWidth = val ? 80 : 1;
  }
  // TODO 补齐作用
  handlerSuffixSelectIcon() {
    this.iconDialogVisible_suffix = true;
  }
  // TODO 补齐作用
  handlerPrefixSelectIcon() {
    this.iconDialogVisible_prefix = true;
  }
  // TODO 补齐作用
  addRuleItem() {
    this.props.rules.push({
      rule: "",
      msg: "",
    });
  }
  // TODO 补齐作用
  handlerChangeRulesType(val: any) {
    //@ts-ignore
    const obj = defaultRules[val];
    console.log(obj);
    if (obj != undefined) {
      this.props.rules.push({
        rule: obj.rule,
        msg: obj.msg,
      });
    }
  }
  // TODO 补齐注释
  // 数据属性
  handlerChangeIdCallback?: Function;

  // 方法
  handlerChangeGetId(val: any) {
    if (this.handlerChangeIdCallback) {
      this.handlerChangeIdCallback(val);
    }
  }
}
</script>
<style scoped>
.input {
  width: 75%;
}

.rule-item {
  padding-top: 5px;
  padding-bottom: 5px;
}

.close-btn {
  text-align: center;
}

.close-icon:hover {
  cursor: pointer;
}

.close-btn :deep(.el-icon-remove-outline) {
  color: red;
}
</style>
